package com.example.ssss.ui.dashboard;

import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.example.ssss.DrivingDetectionActivity;
import com.example.ssss.PretestActivity;
import com.example.ssss.databinding.FragmentDashboardBinding;
import com.example.ssss.request.DashboardRequestViewModel;
import com.example.ssss.state.DashboardStateViewModel;

public class DashboardFragment extends Fragment {

    private DashboardStateViewModel dashboardStateViewModel;//与ViewModel进行交互，从后台取数据
    private DashboardRequestViewModel dashboardRequestViewModel;
    private FragmentDashboardBinding binding;//与layout进行绑定，实时更新数据
    private Button btn;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        dashboardStateViewModel =
                new ViewModelProvider(this).get(DashboardStateViewModel.class);
        dashboardRequestViewModel =
                new ViewModelProvider(this).get(DashboardRequestViewModel.class);

        binding = FragmentDashboardBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        btn=binding.startPretest;
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startPretesting();
            }
        });
        btn.setVisibility(View.INVISIBLE);

        /*final TextView textView = binding.textDashboard;
        dashboardViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                textView.setText(s);
            }
        });*/
        startPretesting();
        return root;
    }

    @Override
    public void onStop() {
        super.onStop();
        btn.setVisibility(View.VISIBLE);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
    public void startPretesting(){
        //跳转到全屏检测页面
        Intent intent = null;
        intent = new Intent(getActivity(), PretestActivity.class);
        this.startActivity(intent);
    }
}